package com.avocado.bt.abs;

import com.avocado.bt.BTState;
import com.avocado.bt.IBTContext;
import com.avocado.bt.IBTNode;

/**
 * @Author: zsh
 * @Date: 2023/10/16 16:34
 */
public abstract class BaseNode implements IBTNode {
    private IBTNode parent;
    private BTState state;
    private String nodeName;
    private IBTContext context;
    private final String param;

    public BaseNode(String param) {
        this.param = param;
    }

    @Override
    public BTState tick() {
        if (state != BTState.Running) {
            initialize(context);
        }

        state = update(context);

        if (state != BTState.Running) {
            terminate(context);
        }
        return state;
    }

    @Override
    public void initialize(IBTContext context) {

    }

    @Override
    public void terminate(IBTContext context) {
    }

    @Override
    public BTState getState() {
        return state;
    }

    @Override
    public void setState(BTState state) {
        this.state = state;
    }

    @Override
    public String getNodeName() {
        return nodeName;
    }

    @Override
    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    @Override
    public IBTNode getParent() {
        return parent;
    }

    @Override
    public void setParent(IBTNode node) {
        this.parent = node;
    }

    @Override
    public void setContent(IBTContext context) {
        this.context = context;
    }

    public String getParam() {
        return param;
    }


}
